package com.lantu.wisdom.controller;


import com.lantu.framework.common.constants.exceptions.ASException;
import com.lantu.framework.common.utils.PageQueryResult;
import com.lantu.framework.common.utils.ResponseWrapper;
import com.lantu.wisdom.common.utils.SensitiveWordUtil;
import com.lantu.wisdom.dto.*;
import com.lantu.wisdom.dto.vo.GetQuestionDetailVO;
import com.lantu.wisdom.model.WUser;
import com.lantu.wisdom.service.WAppraisalTypeApi;
import com.lantu.wisdom.service.WQuestionApi;
import com.lantu.wisdom.service.WUserApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zch
 * @since 2021-06-15
 */
@RestController
@RequestMapping("/wQuestion")
@Api(tags = {"问题相关"})
public class WQuestionController {


    @Autowired
    WQuestionApi questionApi;

    @Autowired
    WUserApi userApi;

    @ApiOperation(value = "添加问题")
    @RequestMapping(value = "/addQuestion", method = RequestMethod.POST)
    public ResponseWrapper addQuestion(@RequestBody @Validated AddQuestionDTO dto) {
        //SensitiveWordUtil.paramSensitiveWord(dto.toString());
        return questionApi.addQuestion(dto) ? ResponseWrapper.success() : ResponseWrapper.exception();
    }

    @ApiOperation(value = "是否可以添加问题")
    @RequestMapping(value = "/whetherAdd/{userId}", method = RequestMethod.GET)
    public ResponseWrapper whetherAdd(@PathVariable String userId) {

        return questionApi.whetherAdd(userId) ? ResponseWrapper.success() : ResponseWrapper.exception();
    }

    @ApiOperation(value = "获取问题列表")
    @RequestMapping(value = "/getQuestion/{userId}", method = RequestMethod.GET)
    public ResponseWrapper<GetQuestionDTO> getQuestion(@PathVariable String userId) {
      List<GetQuestionDTO> list=  questionApi.getQuestion(userId);
      return ResponseWrapper.success(list);
    }

    @ApiOperation(value = "获取问题列表")
    @RequestMapping(value = "/getAllQuestion", method = RequestMethod.POST)
    public ResponseWrapper<PageQueryResult<GetAllQuestionDTO>> getQuestion(@RequestBody SearchQuestionDTO searchQuestionDTO) {
        PageQueryResult<GetAllQuestionDTO> allQuestion = questionApi.getAllQuestion(searchQuestionDTO);

        return ResponseWrapper.success(allQuestion);
    }

    @ApiOperation(value = "获取问题详情")
    @RequestMapping(value = "/getQuestionDetail/{questionId}", method = RequestMethod.GET)
    public ResponseWrapper<GetQuestionDetailVO> getQuestionDetail(@PathVariable Integer questionId) {
        GetQuestionDetailVO questionDetail=  questionApi.getQuestionDetail(questionId);
        return ResponseWrapper.success(questionDetail);
    }

}

